/*
直接更新 state 的多个方法的对象
*/
import { setToken } from '../util/util'
import dayjs from 'dayjs'

export default {
  setToken (state, token) {
    state.token = token
    setToken(token)
  },

  //获取加油区和超市服务数据
  GETSERVICETIMEDATA(state,{serviceData}){
    if(serviceData.category === "refuel_side"){
      delete serviceData.category
      state.refuelServiceData = serviceData
    }
    else{
      delete serviceData.category
      state.checkoutServiceData = serviceData
      state.countData[0].value = serviceData.serviceTotalCount
      state.countData[2].value = Math.round(serviceData.serviceTotalAverageTime)+"分钟"
    }
  },

  //获取加油区和超市的违规率
  GETVIOLATERATE(state,{violateRateData}){
    if(violateRateData.category === "refuel_side"){
      state.violateRate.refuelViolateRate = violateRateData.violateRate
    }
    else{
      state.violateRate.checkoutViolateRate = violateRateData.violateRate
      state.countData[3].value = (violateRateData.violateRate * 100) . toFixed(2) + "%"
    }
  },

   // 获取卸油次数，保险柜打开次数，钱箱打开次数
   GETSTATIONCENTERCOUNTDATA (state, { countData }) {
    state.stationCenterCountData[0].value = countData.unloadCount + '次'
    state.stationCenterCountData[2].value = countData.safeboxCount + '次'
    state.stationCenterCountData[3].value = countData.moneyboxCount + '次'
  },

  // 获取 事件表格数据
  GETEVENTSTABLEDATA (state, {eventTableData}) {
    state.eventTableData = eventTableData
  },

  //获取评分
  GETSCORE(state,{scoreData}){
    state.stationScoreData = scoreData
  },

  // 获取 站点历史综合评分指标
  GETSTATIONSCORETRENDDATA (state, { scoreListData}) {
    state.stationScoreListData = scoreListData
  },

  // 获取站点视频流地址
  GETSTATIONVIDEOSTREAMURL (state, {videoList}) {
    state.stationVideoStreamUrl = videoList
    state.monitorData.videoInfoList = videoList
    state.getStreamUrlState = 200
  },
  // 更新视频流获取状态到 404
  CHANGEGETVEDIOSTREAMSTATE404 (state) {
    state.videoPlayerState.getStreamUrlState = 404
  },
  // 更新视频流获取状态到 200
  CHANGEGETVEDIOSTREAMSTATE200 (state) {
    state.videoPlayerState.getStreamUrlState = 200
  },  

  // 加载视频流实时播放页面
  ONLOADVIDEOSTREAMPLAYER (state, {reqPlayerInfo}) {
    state.monitorData.isLoadPlayer = true // false 为不加载，true 为显示视频流播放页面
    state.monitorData.reqPlayerInfo = reqPlayerInfo
  },

  // 关闭视频流详情页，打开视频流网格页面
  CLOSEDETAILSLOADVIDEOGRIDPAGES (state) {
    state.monitorData.isLoadPlayer = false
    state.monitorEventsTableListData = []
  },

  //更新变化趋势数据
  GETMONITOREVENTSTABLELIST (state, {tableData}) {
    state.monitorEventsTableListData = tableData
  },

  // 更新选择的站点数据
  UPDATESELECTEDDATETIME (state, {selectedData}) {
    state.selectedDateTime = selectedData
  },

  // 获取商超进店人次
  GETCUSTOMERENTER (state, {getCustomerEnterData}) {
    state.countData[1].value = getCustomerEnterData.enterPersonsSum
    state.enterPersonsData = getCustomerEnterData.enterPersonsData
  },
  
  // 获取站长在站率, 没有实时数据，只有周数据和月数据
  GETMANAGERONLINERATE (state, {getManagerOnlineRateData}) {
    state.managerOnlineRateData = getManagerOnlineRateData.managerOnlineRateData
  },

  // 获取加油站违规事件数据
  GETVIOLATEEVENTDATA (state, { violateData }) {
    state.violateEventData = violateData
  },

  // 获取 拥堵指数数据
  GETJAMINDEXDATA (state, {jamIndex}) {
    state.jamIndexData = jamIndex
  },

  // 获取 加油岛服务时间
  GETHISTORYREFUELSERVICETIMEDATA (state, {refuelServiceIndexName, refuelServiceIndexTime}) {
    state.refuelServiceName = refuelServiceIndexName
    state.refuelServiceTime = refuelServiceIndexTime
  },

  //保存用户信息
  SET_USER(state,{userinfo}){
    state.userInfo= userinfo
  },
  //设置登录状态
  SET_LOGIN_STATUS(state,bool){
    state.loginStatus = bool
  },


  //获取视频列表
  GET_VIDEO_LIST(state,{videoList}){
    state.videoList = videoList
  },

  GET_MONITOR_STATUS(state,{monitorStatusData}){
    state.monitorStatusData = monitorStatusData
  },

  GET_VIDEO_INFO(state,{videoStatus,historyData}){
    state.videoStatus = videoStatus
    state.historyData = historyData
  },

  HANDLE_TRIGGER(state,{videoStatus}){
    state.videoStatus = videoStatus
    // let todayRealTime = dayjs().add(1, 'hour').format("YYYY-MM-DD HH:mm:ss")
    // let data = {
    //   datetime:todayRealTime,
    //   status:"饱和度低"
    // }
    // let preData = state.historyData
    // preData.push(data)
    // state.historyData= preData
  }

   // // 更新 站点视频流 推流状态
  // UPDATESTATIONVIDEOSTREAMSTATE (state, {videoList}) {
  //   if(state.stationVideoStreamUrl.length === 0) return
  //   videoList.forEach((ele, index) => {
  //     if(ele.channel ===  state.stationVideoStreamUrl[index].channel) {
  //       state.stationVideoStreamUrl[index].pushing = ele.pushing
  //     }
  //   })
  // },

  // // 初始化所有状态数据
  // INITALLSTATEDATA (state) {
  //   state.servicePersonsData = [] // 服务人次
  //   state.enterPersonsData = [] // 进店人次
  //   state.avgServiceTimeData = [] // 平均服务时间
  //   state.managerOnlineRateData = [] // 站长在站率数据

  //   // 违规事件统计
  //   state.violateEventData.checkoutVE = []
  //   state.violateEventData.refuelVE = []
  //   state.violateEventData.safeboxVE = []
  //   state.violateEventData.unloadVE = []

  //   // 站点 历史评分数据
  //   state.stationScoreListData = {
  //     overall: [], // 总评分
  //     safety: [], // 安全评分
  //     efficiency: [], // 效率评分
  //     management: [], // 管理评分
  //     service: [], // 服务评分
  //     checkout: [], // 便利店
  //     refuel: [], // 加油区
  //     safebox: [], // 财务室
  //     unload: [] // 卸油口
  //   }

  //   state.jamIndexData = [], // 拥堵指数
  //   // 加油区服务数据
  //   state.refuelServiceData.serviceCarsData = []
  //   state.refuelServiceData.avgServiceTimeData = []
  //   state.refuelServiceName = [], // 加油岛名称
  //   state.refuelServiceTime = [] // 加油岛对应服务时间
  // },

}


